// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Resources;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace QuoteAdvantage
{
	/// <summary>
	/// Summary description for GenerateSampleData.
	/// </summary>
	public class GenerateSampleData : System.Web.UI.Page
	{
      private Engine eng = null;
      protected ResourceManager m_mgrResource;
      protected System.Web.UI.WebControls.Label Label1;
      protected System.Web.UI.WebControls.Label Label2;
      protected System.Web.UI.WebControls.Label Label3;
      protected System.Web.UI.WebControls.TextBox txtOrganizationId;
      protected System.Web.UI.WebControls.TextBox txtDefaultUomScheduleId;
      protected System.Web.UI.WebControls.TextBox txtDefaultUomId;
      protected System.Web.UI.WebControls.Button btnGenerate;
   
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
         this.btnGenerate.Click += new System.EventHandler(this.btnGenerate_Click);
         this.Load += new System.EventHandler(this.Page_Load);

      }
		#endregion

      private void btnGenerate_Click(object sender, System.EventArgs e)
      {
         m_mgrResource = new ResourceManager("QuoteAdvantage.strings", typeof(CustomizeQuote).Assembly);
         eng = new Engine(this.Trace, m_mgrResource);
         
         Guid guidOrganizationId = new Guid(txtOrganizationId.Text);
         Guid guidDefaultUomScheduleId = new Guid(txtDefaultUomScheduleId.Text);
         Guid guidDefaultUomId = new Guid(txtDefaultUomId.Text);
         
         CreateProduct("Model 12 Notebook", 650, "NB-12", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
        
         CreateProduct("Model 10 Notebook", 699, "NB-10", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 10A Notebook", 799, "NB-10A", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 50 Notebook", 999, "NB-50", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 50X Notebook", 1088, "NB-50X", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 1000 Server", 799, "SC-1000", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 2000 Server", 899, "SC-2000", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 4000 Server", 1200, "SC-4000", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 5000 Server", 1800, "SC-5000", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 8000 Server", 2599, "SC-8000", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 9000 Server", 2999, "SC-9000", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 2 Home Computer", 499, "HC-2", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Model 6 Home Computer", 999, "HC-6", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);

         CreateProduct("Windows XP Home", 199, "OS-XPH", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Windows XP Professional", 299, "OS-XPP", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Windows Server 2003", 969, "OS-WS03", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Penguin Linux", 92, "OS-PL", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);

         CreateProduct("Microsoft Office Professional", 450, "OFF-1", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Penguin Open Office", 24.95, "OFF-2", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);

         CreateProduct("Internal CD-ROM Drive", 32, "MD-1", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Internal CD-RW Drive", 77, "MD-2", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Internal 16x DVD-ROM Drive", 32, "MD-3", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("Internal DVD +/-RW +R", 95, "MD-4", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
 
         CreateProduct("CD Maker Plus Software", 24.95, "SFT-1", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("SuperDVD Player Software", 44.99, "SFT-2", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("DVD Creator Home Edition", 58, "SFT-3", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         
         CreateProduct("250 GB Hard Drive", 69.99, "HD-1", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("400 GB Hard Drive", 114.99, "HD-2", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);
         CreateProduct("500 GB Hard Drive", 164.99, "HD-3", guidOrganizationId, guidDefaultUomScheduleId, guidDefaultUomId);

      }

      private bool CreateProduct(string strName, double nPrice, string strProductNumber,
                           Guid guidOrganizationId, Guid guidDefaultUomScheduleId, Guid guidDefaultUomId)
      {
         bool  bResult = true;

         try
         {
            Product  objMyProduct = new Product();

            objMyProduct.Name = strName;
            //  objMyProduct.Description = "Testing";
            objMyProduct.Price = new Decimal(nPrice);
            objMyProduct.ProductNumber = strProductNumber;
            objMyProduct.DefaultUnitOfMeasureId = guidDefaultUomId;
            objMyProduct.DefaultUomScheduleId = guidDefaultUomScheduleId;
            objMyProduct.OrganizationId = guidOrganizationId;

            eng.AddProductCatalogEntry(objMyProduct);
         }
         catch (Exception ex)
         {
            throw ex;
           // string strMessage = ex.Message;
           // bResult = false; // Product ID probably already exists
         }

         return bResult;
      }

	} // end class
}
